package East_newsK;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;

public class News_analysis {

    public static void news_analysis(String url ,String css) throws Exception{
        System.setProperty("webdriver.chrome.driver", "E:\\Java\\工具包\\Chromedriver\\chromedriver.exe");//导入对应的驱动程序
        WebDriver driver = new ChromeDriver();
        String content ,title;
        //解析内容
        System.out.println("开始解析内容！");
        driver.get(url);
        title = driver.findElement(By.cssSelector("h1")).getText()+"\n";
        content = title;
        //获取内容
        List<WebElement> list =driver.findElements(By.cssSelector(css));
        for (WebElement webElement : list) {
            content += webElement.getText()+"\n";
        }
        System.out.println("开始储存！");
        Content_storage.storage(content);
        driver.close();
    }
}
